﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ClusterStatus.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The cluster status.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Services.Dto
{
    using System;
    using System.Runtime.Serialization;

    /// <summary>
    /// The cluster status.
    /// </summary>
    [DataContract]
    public class ClusterStatus
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the comments.
        /// </summary>
        [DataMember]
        public string Comments { get; set; }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        [DataMember]
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether is active.
        /// </summary>
        [DataMember]
        public bool IsActive { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        [DataMember]
        public Guid Type { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="status">
        /// The status.
        /// </param>
        /// <returns>
        /// The <see cref="ClusterStatus"/>.
        /// </returns>
        public static ClusterStatus Convert(Models.Domain.ClusterStatus status)
        {
            if (status != null)
            {
                var dto = new ClusterStatus
                              {
                                  ID = status.ID, 
                                  Comments = status.Comments, 
                                  IsActive = status.IsActive, 
                                  Type = status.Type.ID
                              };
                return dto;
            }
            
            return null;
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Queries
{
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Results;

    /// <summary>
    /// The cluster status query.
    /// </summary>
    [DataContract]
    public class ClusterStatusQuery : IQuery
    {
        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <returns>
        /// The <see cref="IResult"/>.
        /// </returns>
        public override IResult Execute(ISession hsession)
        {
            var actioner = new ClusterStatusActioner(hsession, null);

            return actioner.ExecuteSearchQuery(this);
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Results
{
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    using ServiceLibrary.Services.Dto;

    /// <summary>
    /// The cluster status result.
    /// </summary>
    [DataContract]
    public class ClusterStatusResult : IResult
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterStatusResult"/> class.
        /// </summary>
        public ClusterStatusResult()
        {
            this.List = new List<ClusterStatus>();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the list.
        /// </summary>
        [DataMember]
        public List<ClusterStatus> List { get; set; }

        /// <summary>
        /// Gets or sets the total row count.
        /// </summary>
        [DataMember]
        public int TotalRowCount { get; set; }

        #endregion
    }
}

namespace ServiceLibrary.Services.Commands
{
    using System;
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Dto;

    using User = ServiceLibrary.Models.Domain.User;

    /// <summary>
    /// The create cluster status command.
    /// </summary>
    [DataContract]
    public class CreateClusterStatusCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the status.
        /// </summary>
        [DataMember]
        public ClusterStatus Status { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ClusterStatusActioner(hsession, activeUser);
            actioner.CreateClusterStatus(this);
        }

        #endregion
    }

    /// <summary>
    /// The update cluster status command.
    /// </summary>
    [DataContract]
    public class UpdateClusterStatusCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public ClusterStatus Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ClusterStatusActioner(hsession, activeUser);
            actioner.UpdateClusterStatus(this);
        }

        #endregion
    }

    /// <summary>
    /// The delete cluster status command.
    /// </summary>
    [DataContract]
    public class DeleteClusterStatusCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Guid? Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ClusterStatusActioner(hsession, activeUser);
            actioner.DeleteClusterStatus(this);
        }

        #endregion
    }
}